﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace BrsdServer
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class find1 : IHttpHandler
    {
        public static string mac = "";
        public static string ip = "";
        public void ProcessRequest(HttpContext context)
        {
            dnsInfoBLL dnsInfo = new dnsInfoBLL();
            context.Response.ContentType = "text/html";
            mac=context.Request.QueryString["mac"];
            if (mac.Contains(":"))
            {
                string[] str = mac.Split(':');
                mac = "";
                for (int i = 0; i < str.Length;i++ )
                {
                    mac += str[i];
                }
            }
            if (mac.Contains("-"))
            {
                string[] str = mac.Split('-');
                mac = "";
                for (int i = 0; i < str.Length;i++ )
                {
                    mac += str[i];
                }
            }
            string macStr = mac.ToUpper();
            //isEixt标识是否存在，不存在-1，存在但没有绑定为1，存在绑定0
            DataTable isExit = dnsInfo.GetNumMac(macStr);
            
            if (isExit.Rows.Count==0)
            {
                context.Response.Write(-1);
            }
            else
            {
                //isBind=0没有绑定，=1已绑定。
                int isBind = (isExit.Rows[0][7].ToString()==isExit.Rows[0][3].ToString()?0:1);
                ip = isExit.Rows[0][2].ToString();
                if (isBind==0)
                {
                    context.Response.Write(
                            	"<li>DVR外网IP：<span id='ip'>"+isExit.Rows[0][2]+"</span></li>"+
                                "<li>端口："+isExit.Rows[0][11]+"</li>"+
                                "<li>MAC地址："+isExit.Rows[0][3]+"</li>"+
                                "<li>更新时间："+isExit.Rows[0][4]+"</li>"
                        
                    );
                }
                else
                {
                    context.Response.Write(0);
                }
            }
            

            //if (isExit == -1)
            //{
            //    string strScript = "<script type='text/javascript'>alert('您查找的MAC地址不存在');</script>";
            //    Page.ClientScript.RegisterStartupScript(this.GetType(), "", strScript);
            //}
            //else if (isExit == 1)
            //{
            //    string strScript = "<script type='text/javascript'>alert('您查找的MAC地址已绑定');</script>";
            //    Page.ClientScript.RegisterStartupScript(this.GetType(), "", strScript);
            //}
            //else
            //{
            //    Response.Redirect("main.aspx");
            //}
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
